<?php

namespace app\api\model;

use think\Model;
use think\model\concern\SoftDelete;

class SignInLog extends Model
{
    use SoftDelete;

    protected $name = "signin_log";
    protected $pk = "id";
    protected $deleteTime = "delete_time";
    protected $defaultSoftDelete = 0;
    protected $json = [];
    protected $jsonAssoc = true;
    public static function add($user_id){
        $data = self::where('uid',$user_id)
            ->where('create_time','>=',strtotime(date('Y-m-d').' 00:00:00'))
            ->where('create_time','<=',strtotime(date('Y-m-d').' 23:59:59'))
            ->find();
        if(empty($data)){
            $newdata = [
                'uid'=>$user_id,
                'status'=>1,
                'create_time'=>time(),
                'update_time'=>time(),
            ];
            $bool = self::create($newdata);
        }else{
            $newdata = [
                'update_time'=>time(),
            ];
            $bool = self::where('id',$data['id'])
                ->save($newdata);
        }
        return $bool;
    }
}